package com.yl.auth.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.model.entity.Gangwei;
import com.yl.auth.mapper.GangweiMapper;
import com.yl.auth.service.GangweiService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author
 * @since 2023-06-15
 */
@Service
public class GangweiServiceImpl extends ServiceImpl<GangweiMapper, Gangwei> implements GangweiService {
    @Resource
    private GangweiMapper gangweiMapper;

    @Override
    public boolean saveGangwei(Gangwei gangwei) {
        return gangweiMapper.saveGangwei(gangwei);
    }

    @Override
    public IPage<Gangwei> getAll(Page<Gangwei> page1) {
        return gangweiMapper.getAll(page1);
    }


    @Override
    public void updateQuanXian(Integer id, List<Integer> quanxianList) {
        if (id != null) {
            //删除中间表在添加
            gangweiMapper.deleteQuanXian(id);
            if (quanxianList != null && quanxianList.size() > 0) {
                for (Integer quanxianid : quanxianList) {
                    gangweiMapper.addQuanXian(id, quanxianid);
                }
            }
        }
    }

    @Override
    public List<Integer> getQuanXianById(Long id) {
        return gangweiMapper.getQuanXianById(id);
    }

    @Override
    public void addQuanXian(Integer id, List<Integer> quanxianList) {
        if (quanxianList != null && quanxianList.size() > 0) {
            for (Integer quanxianid : quanxianList) {
                gangweiMapper.addQuanXian(id, quanxianid);
            }
        }
    }


}
